package com.imooc.demo;

import java.lang.reflect.Field;

/**
 * Created by joe on 16-7-30.
 */
public class MainTest2 {
	public static void main(String[] args) throws Exception {
		Class<?> cls = Class.forName("com.imooc.pojo.Book2");//获取类 类型
		Object obj = cls.newInstance();//必须给出实例化对象
		Field titleField = cls.getDeclaredField("title");
		titleField.setAccessible(true);//取消封装
		titleField.set(obj, "java开发");//相当于:Book类对象.title = "java开发";
		System.out.println(titleField.get(obj));
	}
}
